package com.zq.designpaterns.behavior.responsibility;

/**
 * ================================================
 * 作    者：程志强
 * 邮    箱：cheng.zhiqiang@cesgroup.com.cn
 * 版    本：1.0.0
 * 创建日期：2021/01/13  16:57
 * 修改日期：
 * 描    述：
 * 修订历史：
 * ================================================
 */
public abstract class AbstractLogger {
    public static int INFO = 1;
    public static int DEBUG = 2;
    public static int ERROR = 3;

    protected int level;
    /**
     * 责任链中的下一个元素
     */
    protected AbstractLogger nextLogger;

    public void setNextLogger(AbstractLogger nextLogger) {
        this.nextLogger = nextLogger;
    }

    public void logMessage(int level,String message){
        if (this.level<=level){
            write(message);
        }
        if (null!=nextLogger){
            nextLogger.logMessage(level,message);
        }
    }

    protected abstract void write(String message);

}
